﻿$().ready(function () {
    $("#form").validate({
        //        errorPlacement: function (error, element) {
        //            error.appendTo($("#summary"));
        //        },
        showErrors: function (errorMap, errorList) {
            if (errorList.length != 0) {
                $.Msg.errorTips("您的表单填写不完整:", 0, errorList);
            }
        },
        rules: {
            TourName: "required"
        },
        messages: {
            TourName: "线路名称为必填项"
        },
        /* 获得焦点时不验证 */
        focusInvalid: false,
        onkeyup: false
    });
})

$(function () {
    initProvince("#ProvinceID");
    initCity("#CityID");
    datePicker("#LeaveDate");
    datePicker("#ReceiveTeamTime");
    datePicker("#DeliverTeamTime");
    $.ctrl.employeeDropdownList("TourCtrlName", "TourCtrlID");
    $.ctrl.employeeDropdownList("HotelCtrlName", "HotelCtrlID");
    $.ctrl.employeeDropdownList("CarCtrlName", "CarCtrlID");
    $.ctrl.employeeDropdownList("DutyOfficer", "DutyOfficerID");
    $.ctrl.enterDropdownList("ClientName", "ClientID", 0, 1,
        function (src, data) {
            var arrmp = data.value.split(",");
            $("#ClientID").attr("value", arrmp[0]);
            $("#ClientName").attr("value", arrmp[1]);
            $("#Linkman").attr("value", arrmp[2]);
            $("#LinkmanTel").attr("value", arrmp[3]);

        }
    );
    LoadShoppingCbk();
    $("#tabs").tabs();
    GuideRequire();
})

//导游要求
function InputGuideRequire() {
    var strRequire = "";
    var ItemGuideRequire = $(".Guiderequre");
    var ObjGuide = $("#TourGuideRequire");
    for (var i = 0; i < ItemGuideRequire.length; i++) {
        if (ItemGuideRequire.eq(i).attr("checked") == true) {
            strRequire += ItemGuideRequire.eq(i).val() + ",";
        }
    }

    ObjGuide.attr("value", strRequire);

}

//确认单标准默认值
function defaultRequire(defVal, objID) {
    $("#" + objID + "").attr("value", defVal);
}


//全程无购物时不能选中购物店
function Noshopping() {
    var obj = $(".chkshopBox");
    if ($("#chkNoshop").attr("checked") == true) {
        for (var i = 0; i < obj.length; i++) {
            obj.eq(i).attr("checked", false);
        }
    }
}

//选中购物店时不能选中全程无购物
function CheckStore() {
    var obj = $(".chkshopBox");
    for (var i = 0; i < obj.length; i++) {
        if (obj.eq(i).attr("checked") == true) {
            $("#chkNoshop").attr("checked", false);
        }
    }
}

//读取购物店复选,存在选中
function LoadShoppingCbk() {
    if ($("#hideStoreList").val() == ",0,") {
        $("#chkNoshop").attr("checked", true);
    }
}


//根据导游要求数据默认选中值
function GuideRequire() {
    var Require = $("#hideTourGuideRequire").val();
    var ItemGuideRequire = $(".Guiderequre");
    var temp = Require.split(',');
    for (var i = 0; i < temp.length; i++) {
        for (var j = 0; j < ItemGuideRequire.length; j++) {
            if (temp[i] == ItemGuideRequire.eq(j).val()) {
                ItemGuideRequire.eq(j).attr("checked", true);
            }
        }
    }
}
